package com.hyy.book2.model;

import lombok.Getter;

import java.util.Arrays;

@Getter//根据状态码，赋值字符串（可借阅、不可借阅...）
public enum BookStatusEnum {

    DELETE(0,"删除"),
    NORMAL(1,"可借阅"),
    FORBIDDEN(2,"不可借阅");
    private Integer code;
    private String desc;

    BookStatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    //通过状态码，赋值字符串
    public static BookStatusEnum getStatusByCode(Integer code) {
        return Arrays.stream(BookStatusEnum.values()).filter(x -> x.getCode() == code).findFirst().get();
    }
}
